/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ugc.cnel.manabi.bakenbeans.validadores;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Admin
 */
public class email implements Validator{
    private static final String EMAIL="^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$";
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        Pattern patron = Pattern.compile(EMAIL);
        String email=(String)value;
        Matcher encaja = patron.matcher(email);
        if(!encaja.matches()){
            FacesMessage message = new FacesMessage();
            message.setDetail("eMail ingresado en formato invalido");
            message.setSummary("eMail Ingresado en formato invalido");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(message);
        }
    }

}
